import sys
import os
import logging
import djalog
import shutil

from utils import joinpaths, unzip_to_tmpdir

djalog.configure(LOG_LEVEL=logging.INFO, LOG_USE_COLORS=True)

TEST_DIR = os.path.dirname(__file__)
ROOT_DIR = joinpaths(TEST_DIR, '..')
TMP_DIR = joinpaths(TEST_DIR, 'tmp')
print "Temp dir set to:", TMP_DIR

HG_REPO_ZIP = joinpaths(TEST_DIR, 'static', 'repo_hg.zip')

# If vcbrowser is already installed this is necessary
# in order to include exactly this, not installed one,
# version to tests.
logging.info("Adding %s to sys.path" % ROOT_DIR)
sys.path.insert(0, ROOT_DIR)

def get_or_create_tmpdir():
    """
    Returns path to temp dir used by tests.
    """
    if not os.path.isdir(TMP_DIR):
        os.mkdir(TMP_DIR, 0755)
    return TMP_DIR

def clean_tmpdir():
    """
    Removes temp dir and everything within it.
    """
    if os.path.isdir(TMP_DIR):
        shutil.rmtree(TMP_DIR)

